const FN = require('../../utils/public');
import commonAPI from '../../api/api'
var plugin = requirePlugin("ihearing-eval");// 智聆口语测评（腾讯免费）
let plugin4SEO = requirePlugin("myPlugin");//  智聆语音测评（腾讯付费）
let manager = null;
var ba = wx.getBackgroundAudioManager();
const app = getApp()
import util from '../../utils/util.js';
Page({
  data: {
    evaluationType:'1',// 口语测评模式，1：智聆口语测评（腾讯免费），2：智聆语音测评（腾讯付费），默认1
    cardList: [],
    touchStartTime: 0,
    evadingAudit: {},
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    total: 0,
    currentItemIndex: 0,
    current: 0,
    priTmplIdArr: [], // 数据库查询出来的订阅消息集合
    scoreDetail: {},// 当前跟读信息
    adObj: {},
    wxUserInfo:{},
    btnimgarr: [1, 1, 1],
    tempFile:{},// 跟读者的音频临时路径
    repeating: false,// 正在跟读gif标识
    integralObj:{},// 积分对象
    pointsConfig4translateLowScoreWords: {},// 低分单词積分配置
    pointsConfig4AIErrorCorrection: {},// AI纠音積分配置
  },

  onLoad: function (options) {
    this.adInit();
    this.setData({
      voiceSystemId: options.voiceSystemId,
      bookChapteId: options.bookChapteId
    })
    this.initData();
    this.getSubscribeMsg();
    this.initOthderData();
  },

  /*
  1. 获取积分主表id
  2. 获取微信小程序信息->设置当前纠音模型
  */  
  initOthderData(){
    const item = app.globalData.miniappInfo.pointsconfigList.find(item=>item.pointsConfigKey == 'translateLowScoreWords');
    const item4AIErrorCorrection = app.globalData.miniappInfo.pointsconfigList.find(item=>item.pointsConfigKey == 'AIErrorCorrection');
    
    const that = this;
    setTimeout(function(){
      that.setData({
        evaluationType:app.globalData.miniappInfo.miniappInfoModel,
        evadingAudit: app.globalData.evadingAudit,
        pointsConfig4translateLowScoreWords:item,// 单词翻译
        pointsConfig4AIErrorCorrection:item4AIErrorCorrection//  AI纠音
      })
    },1000)
  },

  // 初始化测评模型
  initManagerModel(){
      if(this.data.evaluationType == '1'){
        manager = plugin.getRecordRecognitionManager()// 智聆口语测评
      }else{
        this.initTengxunSOE();// 腾讯云智聆语音测评初始化
      }
  },

  adInit() {
    var that = this;
    var pageUrl = util.getCurrentPageUrl()
    var item = app.globalData.advertisement.find(obj => obj.advertisementPage === pageUrl)
    that.setData({
      adObj: item
    })
  },

  // 历史纠音
  correctHistory: function (e) {
    var vsid = e.currentTarget.dataset.vsid, vstitle = e.currentTarget.dataset.vstitle;
    wx.navigateTo({
      url: '../correctGather/correctGather?vsId=' + vsid + '&vsTitle=' + vstitle
    })
  },

  initData() {
    var that = this;
    commonAPI.getAllVSBybookId({ bookChapteId: that.data.bookChapteId, pageNum: 1, pageSize: 9999 }).then(res => {
      if (res.code == '200') {
        const index = res.data.list.findIndex(item => item.voiceSystemId == that.data.voiceSystemId)
        res.data.list.map(function (item, i, array) {
          if (item.hasOwnProperty('hasrepeat')) {// 已跟读过，需要根据跟读结果给文本标识不同颜色。
            const {voiceResultInfo,oldWords} = that.formatWord(item.voiceToen,item)
            item.voiceResultInfo = voiceResultInfo;
          }
          item.words = that.sentenceSplit(item.voiceToen)
        })
        that.setData({
          total: res.data.total,
          current: index,
          currentItemIndex: index,
          cardList: res.data.list
        })
      }
    })
  },

  // 有跟读结果的，文本依旧保留原有文字，只是改变颜色而已
  formatWord(oldWordStr, item) {
    const oldWords = oldWordStr.trim().split(/\s+/);
    const voiceResultInfo = typeof item.voiceResultInfo =='string' ? JSON.parse(item.voiceResultInfo):item.voiceResultInfo;
    if(item.voiceResultAIModel == '1'){
      voiceResultInfo.result.words.forEach((wordObj, index) => {
        if (oldWords[index]) {
          wordObj.word = oldWords[index];
        }
      });
    }else{
      voiceResultInfo.Words.forEach((wordObj, index) => {
        if (oldWords[index]) {
          wordObj.Word = oldWords[index];
        }
      });
    }
    return {voiceResultInfo,oldWords}
  },

  // 听原音
  listenVoice: function (e) {
    var that = this,
      btnObjState = "btnimgarr[0]";
    const index = e.currentTarget.dataset.index;
    const obj = this.data.cardList[index];
    that.setData({
      [btnObjState]: 2
    })
    this.subscribeMsg();
    if (obj.voiceFileType == '2') {
      this.playSMvoiceFile(obj);// 播放小音频
    } else {
      this.playVoiceByTimes(obj);// 播放时间段模式
    }
  },

  // 订阅消息
  subscribeMsg() {
    var that = this;
    wx.requestSubscribeMessage({
      tmplIds: that.data.priTmplIdArr,
      success(res) { },
      fail(res) { console.log("取消订阅", res) }
    })
  },

  // 播放整段音频，小音频
  playSMvoiceFile(obj) {
    var that = this, btnObjState = "btnimgarr[0]";
    ba.src = obj.voiceSystemURL;
    ba.title = obj.voiceToen;
    // ba.play();
    // 播放结束
    ba.onEnded(function () {
      that.setData({
        [btnObjState]: 1
      })
    })
    // 监听背景音频播放错误事件
    ba.onError(function(res){
      console.log("监听背景音频播放错误事件");
      console.log(res);
    });

    // 播放暫停
    ba.onPause(function () {
      that.setData({
        [btnObjState]: 1
      })
    })
  },

  // 播放音频按照时间段，新方法
  playVoiceByTimes(obj) {
    var that = this;
    const bam = wx.getBackgroundAudioManager();
    const star = parseFloat(obj.timing);
    const end = parseFloat(obj.endTiming);
    bam.src = obj.voiceSystemURL
    bam.title = obj.booksName
    bam.epname = obj.bookChapteName// 专辑名，原生音频播放器中的分享功能，分享出去的卡片简介，也将使用该值
    bam.singer = obj.booksName
    bam.coverImgUrl = obj.voiceSystemImage
    bam.startTime = star;
    // bam.play();
    bam.onPlay(function () {
      setTimeout(() => {
        bam.stop();
        var btnObjState = "btnimgarr[0]";
        that.setData({
          [btnObjState]: 1
        })
      }, (end - star) * 1000);
    })
    bam.onError(function () {
      bam.stop()
      var btnObjState = "btnimgarr[0]";
      that.setData({
        [btnObjState]: 1
      })
    })

    // 暂停
    bam.onStop(function () {
      var btnObjState = "btnimgarr[0]";
      that.setData({
        [btnObjState]: 1
      })
    })

    // 播放结束
    bam.onEnded(() => {
      bam.stop()
      var btnObjState = "btnimgarr[0]";
      that.setData({
        [btnObjState]: 1
      })
    })
  },

  // 按照时间段播放声音
  playVoiceByTime(obj) {
    var that = this;
    const star = parseFloat(obj.timing);
    const end = parseFloat(obj.endTiming);
    const audioCtx = wx.createInnerAudioContext();
    audioCtx.src = obj.voiceSystemURL
    audioCtx.autoplay = false;
    audioCtx.startTime = star;
    // audioCtx.play();
    audioCtx.onPlay(function () {
      setTimeout(() => {
        audioCtx.pause();
        var btnObjState = "btnimgarr[0]";
        that.setData({
          [btnObjState]: 1
        })
      }, (end - star) * 1000);
    })

    audioCtx.onStop(function () {
      var btnObjState = "btnimgarr[0]";
      that.setData({
        [btnObjState]: 1
      })
    })

    audioCtx.onEnded(() => {
      audioCtx.stop()
      var btnObjState = "btnimgarr[0]";
      that.setData({
        [btnObjState]: 1
      })
    })
  },

  // 暂停原文
  stopVoice: function (e) {
    var that = this;
    var btnObjState = "btnimgarr[0]";
    that.setData({
      [btnObjState]: 1
    })
    ba.pause();
  },

  noRepeat: function () {
    wx.showToast({
      title: '请先跟读',
      icon: 'none',
      duration: 2000
    });
  },

  // 查看评分详情
  scoreDetail(e) {
    var that = this;
    const vrObj = that.data.cardList[that.data.currentItemIndex];
    wx.navigateTo({
      url: '../sentence/sentence',
      events: {
        // 为指定事件添加一个监听器 ，获取被打开页面传送到当前页面的数据
        acceptDataFromOpenedPage: function (data) {
          console.log(data)
        },
        someEvent: function (data) {
          console.log(data)
        }
      },
      success: function (res) {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', { vrObj })
      }
    })
  },

  // 比较时间戳是否超过31天 开始时间和结束时间
  dateDiff: function (str1, str2) {
    var first = str1 + '', second = str2 + '';
    var datadiff = str2 - str1;
    var time = 31 * 24 * 60 * 60 * 1000;
    if (first.length > 0 && second.length > 0) {
      if (datadiff < 0 || datadiff > time) {
        return false;
      }
      return true;
    }
    return false;
  },

  // 按住
  starFollowup: function (e) {
    this.setData({
      repeating: true
    })
    this.data.touchStartTime = e.timeStamp
    this.stopVoice();
  },

  // 录音
  followup: function () {
    if(this.data.evaluationType == '1'){
      this.freeEvaluation()// 监听录音
      this.initStartOption4free();// 开始录音识别
    }else{
      this.initStartOption4SOE();// 开始录音识别
    }
  },

  // 录音配置(免費模式)
  initStartOption4free(){
    var that = this; 
    const options = {
      duration: 60000,
      content: that.data.cardList[that.data.currentItemIndex].voiceToen,
      evalMode: 'sentence', // 句子
      format: 'mp3', //音频格式，有效值 aac/mp3
      scoreCoeff: 3 // 难度，4最高
    }   
    manager.start(options); // 开始识别
  },

  // 录音配置(soe模式)
  initStartOption4SOE(){
    const voiceToen = this.data.cardList[this.data.currentItemIndex].voiceToen;
    let evalMode = this.getEvaluationMode()
    console.log('evalMode',evalMode)
    const options4SOE = {
      content: voiceToen,
      evalMode,// 0：词模式（中文评测模式下为文字模式），1：句子模式，2：段落模式，3：自由说模式，当为词模式评估时
      duration: 60000,
      scoreCoeff: 2.5, // [1.0 - 4.0] 范围内的浮点数，用于引擎评分的严格程度
      serverType: 0,// 评估语言，0：英文，1：中文。
      textMode: 0,// 输入文本模式，0: 普通文本，1: 音素结构文本      
    }
    manager.start(options4SOE); // 开始识别
  },

  // 评估模式
  getEvaluationMode(){
    const words = this.data.cardList[this.data.currentItemIndex].voiceToen;
    return words.includes(' ') ? 1:0
  },

  // 松开
  endFollowup: function (e) {
    manager.stop()
    this.setData({
      repeating: false
    })
  },

  // 监听swiper滑动
  listenSwiperTab: function (ev) {
    this.setData({
      currentItemIndex: ev.detail.current
    })
  },

  // 上传录音到七牛 
  subVoiceInfo: function () {
    var that = this, filePath = that.data.evaluationType == '1' ? that.data.scoreDetail.tempFilePath:that.data.tempFile.tempFilePath, fileName = new Date().getTime() + ".mp3", 
    data = {
      homeworkId: null,
      voiceResultAccuracy: that.data.evaluationType == '1' ? that.getaverage(that.data.scoreDetail) : that.data.scoreDetail.PronAccuracy.toFixed(1),
      "voiceSystemId": that.data.cardList[that.data.currentItemIndex].voiceSystemId,
      "bookId": that.data.cardList[that.data.currentItemIndex].booksId,
      integralReq:{integralId:that.data.integralObj.integralId},
      voiceResultInfo: JSON.stringify(that.data.scoreDetail),
      voiceResultAIModel:that.data.evaluationType,// AI纠音模型
      voiceResultEvalMode:this.getEvaluationMode(),// 评估模式
      integraldetailReq:{
        integralDetailType:that.data.pointsConfig4AIErrorCorrection.pointsConfigType,
        integralDetailDesc:that.data.pointsConfig4AIErrorCorrection.pointsConfigName,
        integralDetailNum:that.data.pointsConfig4AIErrorCorrection.pointsConfigType === "1" ? that.data.pointsConfig4AIErrorCorrection.pointsConfigValue : -that.data.pointsConfig4AIErrorCorrection.pointsConfigValue
      }
    };
    util.initQiniu();
    // 向七牛云上传
    util.qiniuUploaderUpload(filePath,fileName,(res)=>{
      data.myVoiceurl = res.fileURL;
      that.saveVoiceInfo(data);
    })
  },

  // 提交跟读者语音信息 保存用户的平均分 
  saveVoiceInfo: function (data) {
    var that = this;
    commonAPI.vrSaveVoiceResult({ ...data }).then(res => {
      if (res.code == '200') {
        var scoreDetailObj = "scoreDetail.voiceResultId";
        var hasrepeat = "cardList[" + that.data.currentItemIndex + "].hasrepeat";
        var voiceResultId = "cardList[" + that.data.currentItemIndex + "].voiceResultId";
        that.setData({
          [scoreDetailObj]: res.data,
          [voiceResultId]: res.data,
          [hasrepeat]: "111111"
        })
      }
    })
  },

  errorWoldTool: function (obj) {
    var that = this, errorWords = new Array(), obj = that.data.cardList[that.data.currentItemIndex].voiceResultInfo;
    for (var i = 0; i < obj.result.words.length; i++) {
      if (parseInt(obj.result.words[i].pron_accuracy) <= 90 && obj.result.words[i].word != "*") {
        errorWords.push(obj.result.words[i].word);
      }
    }
    var errorWordObjTemp = {};
    errorWordObjTemp.errorWordsArr = errorWords;
    errorWordObjTemp.vsId = that.data.cardList[that.data.currentItemIndex].voiceSystemId;
    that.setData({
      errorWordsObj: errorWordObjTemp
    })
  },

  errorWoldTool4SOE: function (obj) {
    var that = this, errorWords = new Array(), obj = that.data.cardList[that.data.currentItemIndex].voiceResultInfo;
    for (var i = 0; i < obj.Words.length; i++) {
      if (parseInt(obj.Words[i].PronAccuracy) <= 90 && obj.Words[i].Word != "*") {
        errorWords.push(obj.Words[i].Word);
      }
    }
    var errorWordObjTemp = {};
    errorWordObjTemp.errorWordsArr = errorWords;
    errorWordObjTemp.vsId = that.data.cardList[that.data.currentItemIndex].voiceSystemId;
    that.setData({
      errorWordsObj: errorWordObjTemp
    })
  },

  // 错误单词
  errorWords: function (e) {
    var currWord = e.currentTarget.dataset.errorword, that = this,
      errorArr = new Array(),
      errorObj = {},
      that = this;
      const voicesystemObj = that.data.cardList[that.data.currentItemIndex];
      if(voicesystemObj.voiceResultAIModel == "1"){
        that.errorWoldTool(); 
      }else{
        that.errorWoldTool4SOE(); 
      }
    var temArr = this.data.errorWordsObj.errorWordsArr;
    for (var i in temArr) {
      var obj = {};
      if (temArr[i] == currWord) {
        obj.errorWords = temArr[i];
        obj.vsId = that.data.errorWordsObj.vsId;
        errorArr.unshift(obj);
      } else {
        obj.errorWords = temArr[i];
        obj.vsId = that.data.errorWordsObj.vsId;
        errorArr.push(obj);
      }
    }
    errorObj.errWords = errorArr;
    wx.navigateTo({
      url: '../errorWords/errorWords?errorwords=' + JSON.stringify(errorObj)
    })
  },

  // 计算用户的平均分
  getaverage: function (res) {
    var total = 0, average = 0;
    res.result.words.map(function (item, i, arr) {
      total += item.pron_accuracy == -1 ? 0 : item.pron_accuracy
    })
    average = (total / res.result.words.length).toFixed(1);
    return average;
  },

  // 签到 
  saveSignIn: function () {
    commonAPI.signInSaveSignIn({}).then(res => { })
  },

  // 录音测评结果解析 
  analysisTool: function (res) {
    var that = this;
    var obj = {voiceResultInfo:res,voiceResultAIModel:'1'}
    const {voiceResultInfo,oldWords} = that.formatWord(that.data.cardList[that.data.currentItemIndex].voiceToen,obj);
    var btnObjState = "btnimgarr[2]";
    var scoreDetailObj = "scoreDetail.voiceResultId";
    var voiceResultAIModel = "cardList[" + that.data.currentItemIndex + "].voiceResultAIModel";// AI模型
    var hwObj = "cardList[" + that.data.currentItemIndex + "].voiceResultAccuracy";
    var repeatTimes = "cardList[" + that.data.currentItemIndex + "].repeatTimes";
    var tempFilePath = "cardList[" + that.data.currentItemIndex + "].tempFilePath";
    var repeatResultInfo = "cardList[" + that.data.currentItemIndex + "].voiceResultInfo";
    that.setData({
      [voiceResultAIModel]:'1',
      [hwObj]: that.getaverage(res),
      scoreDetail: res,
      [scoreDetailObj]: that.data.cardList[that.data.currentItemIndex].voiceResultId,
      [tempFilePath]: res.tempFilePath,
      [repeatResultInfo]: voiceResultInfo,
      [btnObjState]: 1,
      [repeatTimes]: that.data.cardList[that.data.currentItemIndex].repeatTimes == null ? 1 : ++that.data.cardList[that.data.currentItemIndex].repeatTimes
    });
  },

  // 录音测评结果解析 
  analysisTool4SOE: function (res) {
    var that = this;
    var obj = {voiceResultInfo:res,voiceResultAIModel:'2'}
    const {voiceResultInfo,oldWords} = that.formatWord(that.data.cardList[that.data.currentItemIndex].voiceToen,obj);
    var btnObjState = "btnimgarr[2]";
    var tempFilePath = "cardList[" + that.data.currentItemIndex + "].tempFilePath";
    var scoreDetailObj = "scoreDetail.voiceResultId";
    var voiceResultAIModel = "cardList[" + that.data.currentItemIndex + "].voiceResultAIModel";// AI模型
    var hwObj = "cardList[" + that.data.currentItemIndex + "].voiceResultAccuracy";// 跟读分数
    var repeatTimes = "cardList[" + that.data.currentItemIndex + "].repeatTimes";// 跟读次数
    var repeatResultInfo = "cardList[" + that.data.currentItemIndex + "].voiceResultInfo";// 跟读结果    
    that.setData({
      [voiceResultAIModel]:'2',
      [hwObj]: res.PronAccuracy.toFixed(1),//当为句子模式时，是所有已识别单词准确度的加权平均值
      scoreDetail: {...that.data.tempFile,...res},
      [tempFilePath]: res.tempFilePath,
      [scoreDetailObj]: that.data.cardList[that.data.currentItemIndex].voiceResultId,
      [repeatResultInfo]: {...voiceResultInfo,...that.data.tempFile},
      [btnObjState]: 1,
      [repeatTimes]: that.data.cardList[that.data.currentItemIndex].repeatTimes == null ? 1 : ++that.data.cardList[that.data.currentItemIndex].repeatTimes
    });
    console.log('voiceResultInfoObj')
    console.log({...voiceResultInfo,...that.data.tempFile})
  },

  // 查看书籍
  aboutBook: function (e) {
    var booksId = e.currentTarget.dataset.booksid;
    wx.navigateTo({
      url: '../myBooksChapter/myBooksChapter?booksId=' + booksId
    })
  },

  // 获取订阅消息
  getSubscribeMsg: function () {
    var that = this;
    commonAPI.getSubscribeMsg({ pageUrl: util.getCurrentPageUrl() }).then(res => {
      if (res.code == '200' && res.data.length > 0) {
        var arr = res.data[0].priTmplIdArr.split(",")
        that.setData({
          priTmplIdArr: arr
        })
      }
    })
  },

  // 根据空白切割单词
  sentenceSplit: function (str) {
    const oldWords = str.trim().split(/\s+/);
    return oldWords
  },

  // 翻译
  translation: function (e) {
    var that = this;
    var words = e.currentTarget.dataset.words
    wx.navigateTo({
      url: '../translationResult/translationResult?words=' + words+'&voiceSystemId='+that.data.cardList[that.data.currentItemIndex].voiceSystemId
    })
  },

  // 初始化智聆语音测评（收费模式）
  initTengxunSOE() {
    var that = this;
    commonAPI.getFederationToken({}).then(res => {
      if (res.code == '200') {
        var obj = JSON.parse(res.data)
        var data = obj.Credentials;
        manager = plugin4SEO.getSoeRecorderManager({
          getAuthorization: function (callback) {
            callback({
              TmpSecretId: data.TmpSecretId,
              TmpSecretKey: data.TmpSecretKey,
              Token: data.Token
            });
          }
        });
        manager.onStart((res) => {
          console.log("成功开始录音识别", res)
        });
        
        /*
        识别结束事件,获取拿到音频数据
        1. 识别结束后，有*，需要处理。
        */ 
        manager.onStop((res) => {
          console.log("识别结束事件",res)
          that.setData({
            tempFile: res
          });
        })
    
        // 识别结果
        manager.onSuccess((res) => {
          console.log('打印识别结果',res)
          if(res.Status == "Finished"){
            that.analysisTool4SOE(res);
            that.subVoiceInfo(); // 同步录音到服务器
            that.saveSignIn(); // 签到
            that.calculateShadowingEligibility();
          }
        })

        manager.onError((res) => {
          //打印错误
          console.log('打印错误',res)
          // FN.Toast(res.Response.Error.Message);
          manager.stop();
        })
      }
    });
  },

  // 智聆口语测评（免费模式）
  freeEvaluation(){
    var that = this;
    manager.onStart = function (res) { // 正常开始录音识别时会调用此事件
      console.log("成功开始录音识别", res);
    }
    // 识别结束事件
    manager.onStop = function (res) {
      if (res.duration < 500) {
        FN.Toast('录音时间过短')
        return;
      }
      if (res.result.words.length == 0) {
        FN.Toast('未检测到声音')
        return;
      }
      that.analysisTool(res);
      that.subVoiceInfo(); // 同步录音到服务器
      that.saveSignIn(); // 签到
      that.calculateShadowingEligibility();
    }
    manager.onError = function (res) { // 异常回调
      FN.Toast(res.msg);
      manager.stop();
      // 20802 小程序请求频率限制,
      if(res.retcode == 20802){
        FN.Toast('AI测评打分高峰期');
        that.setData({
          evaluationType:'2'
        });
        that.updateAImodel();// 更改AI纠音模型
        that.initManagerModel();// 切换AI纠音模型
      }
    }    
  },

  // 测评模式切换
  onChange4evaluationType(event){
    this.setData({
      evaluationType: event.detail
    });
    this.initManagerModel();
  },

  // 修改纠音AI模型:soe模型
  updateAImodel(){
    commonAPI.miniappUpdate({miniappInfoModel:'2'}).then(res=>{})
  },
  
  /**
 * 根据用户积分计算是否可以继续跟读,AI纠音
 */ 
calculateShadowingEligibility() {
  const integralNum = "integralObj.integralNum";
  const num = this.data.integralObj.integralNum;
  this.setData({
    [integralNum]: num - this.data.pointsConfig4AIErrorCorrection.pointsConfigValue
  });
  this.insufficientPoints();
},

// 积分不足提醒
insufficientPoints(){
  if(this.data.integralObj.integralNum<this.data.pointsConfig4AIErrorCorrection.pointsConfigValue){
    this.navigateToPointsPageForVideo(this.data.integralObj.integralNum);
  }
},

// 跳转观看视频获取积分页面
navigateToPointsPageForVideo(integralNum){
  let promise = FN.Confirm(`积分不足，当前积分：${integralNum?integralNum:0}，无法当前操作！`);
  promise.then(res => {
    // wx.navigateTo({
    //   url: '../myIntegral/myIntegral'
    // })
  }).catch(res => {

  });
},

  /**
    * 用户点击右上角分享
    */
  onShareAppMessage: function (res) {
    var that = this;
    let title;

    if (res.from === 'menu') {
      title = '《' + that.data.cardList[that.data.currentItemIndex].booksName + "》 | " + that.data.cardList[that.data.currentItemIndex].bookChapteName
    }
    return {
      title: title,
      imageUrl: that.data.cardList[that.data.currentItemIndex].voiceSystemImage,
    }
  },

  onShow:function(res){
    const that = this;
    this.initManagerModel();
    app.setPageTabBarBadge(); //实时更新主菜单我的消息数字
    app.callbackSignIntegralInfo = res=>{
      that.setData({
        integralObj: res.userInfo.integralObj,
      })
      if(res.userInfo.integralObj.integralNu<that.data.pointsConfig4AIErrorCorrection.pointsConfigValue || res.userInfo.integralObj.integralNum==null){
        that.navigateToPointsPageForVideo(res.userInfo.integralObj.integralNum);
      }
    }
  }  
})